/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.clienterestful.bo;

import com.clienterestful.util.RESTFulservice;
import com.sun.jersey.api.client.UniformInterfaceException;
import com.sun.jersey.api.client.WebResource;
import javax.ws.rs.core.MediaType;

public class CalendarioBO {
    private final String sRecurso="calendario";
    private WebResource  wrRecurso;
    
    public CalendarioBO(){
        //obtenemos el recurso de la coneccion al servicio
        this.wrRecurso= (new RESTFulservice()).getWebResource(this.sRecurso);
    }
    
    public void addCalendarioXML(Object requestEntity)throws UniformInterfaceException{
        WebResource recurso=this.wrRecurso;
        recurso.type(javax.ws.rs.core.MediaType.
                                APPLICATION_XML).post(requestEntity);
    }
    public void addCalendarioJSON(Object requestEntity)throws UniformInterfaceException{
        WebResource recurso=this.wrRecurso; 
        recurso.type(javax.ws.rs.core.MediaType.
                                APPLICATION_JSON).post(requestEntity);
    }
    public void editCalendarioXML(Object requestEntity)throws UniformInterfaceException{
        WebResource recurso=this.wrRecurso; 
        recurso.type(javax.ws.rs.core.MediaType.
                                APPLICATION_XML).put(requestEntity);
    }
    public void editCalendarioJSON(Object requestEntity)throws UniformInterfaceException{
        WebResource recurso=this.wrRecurso;
        recurso.type(javax.ws.rs.core.MediaType.
                                APPLICATION_JSON).put(requestEntity);
    }
    public void deleteCalendario(String idCalendario){
        WebResource recurso=this.wrRecurso;
        recurso.path(java.text.MessageFormat.format("{0}", 
                                new Object[]{idCalendario})).delete();
    }
    
    public <T> T findAllCalendariosPublicosXML(Class<T> responseType)throws UniformInterfaceException{
       WebResource recurso=this.wrRecurso;
       recurso=recurso.path("publicos");
       //System.out.println(recurso.getURI());
       return recurso.accept(MediaType.APPLICATION_XML).get(responseType);
    }
     public <T> T findAllCalendariosPublicosJSON(Class<T> responseType)throws UniformInterfaceException{
       WebResource recurso=this.wrRecurso;
       recurso=recurso.path("publicos");
       return recurso.accept(MediaType.APPLICATION_JSON).get(responseType);
    }
    public <T> T findCitasCalendarioXML(Class<T> responseType, String idCalendario)
    throws UniformInterfaceException{
        WebResource recurso=this.wrRecurso;
        recurso=recurso.path(java.text.MessageFormat.format("{0}/citas", new Object[]{idCalendario}));        
        return recurso.accept(MediaType.APPLICATION_XML).get(responseType);
     }
    public <T> T findCitasCalendarioJSON(Class<T> responseType, String idCalendario)
    throws UniformInterfaceException{
        WebResource recurso=this.wrRecurso;
        recurso=recurso.path(java.text.MessageFormat.format("{0}/citas", new Object[]{idCalendario}));        
        return recurso.accept(MediaType.APPLICATION_JSON).get(responseType);
    }
}
